package com.neuedu.dao.impl;

import com.neuedu.dao.FangChanDao;
import com.neuedu.model.DongShu;
import com.neuedu.model.FangChan;
import com.neuedu.model.XiaoQu;
import com.neuedu.util.DBUtil;

import java.util.List;

public class FangChanDaoImpl implements FangChanDao {
    @Override
    public List<FangChan> selectPageList(Integer limitParams1, Integer limitParams2, String startTime, String endTime, String name) {
        List<FangChan> list = DBUtil.findByWhere(FangChan.class,
                "ruzhushijian >= ? and ruzhushijian <= ? and fangchanmingcheng like ? limit ?,?",
                startTime, endTime, "%" + name + "%", limitParams1, limitParams2);
        return list;
    }

    @Override
    public int selectCount(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(FangChan.class,
                "ruzhushijian >= ? and ruzhushijian <= ? and fangchanmingcheng like ?",
                startTime, endTime, "%" + name + "%").size();

    }

    @Override
    public int add(FangChan fangChan) {
        return DBUtil.insert(fangChan);
    }

    @Override
    public FangChan selectFangChanOne(Integer id) {
        return DBUtil.findOneByWhere(FangChan.class,"id=?",id);
    }

    @Override
    public int updateFangChan(FangChan fangChan) {
        return DBUtil.updateSelective(fangChan,"id=?",fangChan.getId());
    }

    @Override
    public int del(Integer[] ids) {
        String where="id in (";
        for (int i = 0; i < ids.length; i++) {
            where=where+"?";
            if(i!=ids.length-1){
                where=where+",";
            }else{
                where=where+")";
            }
        }
        return DBUtil.delete(FangChan.class,where,ids);
    }

    @Override
    public List<FangChan> selectFangChanByXiaoQuName(String name) {
        List<FangChan> list= DBUtil.findByWhere(FangChan.class,"suoshuxiaoqu=?",name);
        return list;
    }

}
